#include "nemu.h"

const char *regsl[] = {
  "$0", "ra", "sp", "gp", "tp", "t0", "t1", "t2",// 0 - 7
  "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5",// 8 - 15
  "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7",// 16 - 23
  "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6"//24 - 31
};

void isa_reg_display() {
  
  for (int i = 0; i < 32; i++) {
    printf("%s\t: %08x",regsl[i],reg_l(i));
    if (i&1) 
      printf("\n");
    else
      printf("\t|\t");
  }
  printf("\n");
}

uint32_t isa_reg_str2val(const char *s, bool *success) {
  
  int ind = 0;
  while (ind < 32) {
    if (!strcmp(regsl[ind],s)) 
      break;
    ind++;
  }

  *success = !(ind == 32) || !strcmp(s,"pc");

  if(!strcmp(s,"pc"))
    return cpu.pc;
  
  return ind == 32 ? 0 : reg_l(ind);
}
